package com.xbongbong.saas.enums.business;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.ScreenTypeEnum;
import com.xbongbong.saas.enums.SetTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import lombok.Getter;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 供应商模板
 *
 * @author Jian.Wang
 * @version v1.0
 * @date 2019/1/15 14:42
 * @since v1.0
 */
@Getter
public enum SupplierEnum {
    // 供应商模板设置界面显示字段
    // 基本信息
    BASE_INFO("other_1", "enum.supplier.attrName.base_info", "baseInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 10000, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    SUPPLIER_NAME("text_1", "enum.supplier.attrName.supplier_name", "supplierName", FieldTypeEnum.TEXT.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9990, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    SHORT_NAME("text_2", "enum.supplier.attrName.short_name", "shortName", FieldTypeEnum.TEXT.getType(), SetTypeEnum.DISABLE_NONE.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9980, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    PHONE("subForm_1", "enum.supplier.attrName.phone", "phone", FieldTypeEnum.CONTACT_NUMBER.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9970, 1, 1, ScreenTypeEnum.SCREEN_SEARCH.getType()),
    OWNER_ID("ownerId", "enum.supplier.attrName.owner_id", "ownerId", FieldTypeEnum.OWNERID.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 1, 0, ShowTypeEnum.ALL.getCode(), 9960, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    COUSERID("coUserId", "enum.supplier.attrName.couserid", "coUserId", FieldTypeEnum.COUSERID.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 1, 0, ShowTypeEnum.ALL.getCode(), 9950, 1, 0, ScreenTypeEnum.SCREEN_SEARCH.getType()),
    THUMBNAIL("file_1", "enum.supplier.attrName.thumbnail", "thumbnail", FieldTypeEnum.IMAGE.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, ShowTypeEnum.ALL.getCode(), 9940, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    MEMO("text_8", "enum.supplier.attrName.memo", "memo", FieldTypeEnum.TEXTAREA.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_SHOW.getType()),
    // 关联信息
    ASSOCIATED_INFO("other_2", "enum.supplier.attrName.associated_info", "associatedInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9920, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    ADD_SUPPLIER_CONTACT("button_1", "enum.supplier.attrName.add_supplier_contact", "addSupplierContact", FieldTypeEnum.LINK_FORM_BUTTON.getType(), 3, 1, 0, ShowTypeEnum.EDIT.getCode(), 9919, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    PRODUCT_LIST("array_1", "enum.supplier.attrName.product_list", "products", FieldTypeEnum.SELECT_PRODUCT.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9910, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // 扩展信息
    EXTEND_INFO("other_3", "enum.supplier.attrName.extend_info", "extendInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9900, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    QUALITY_STANDARD("num_1", "enum.supplier.attrName.quality_standard", "qualityStandard", FieldTypeEnum.STAR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9890, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    SUPPLY_COST("num_2", "enum.supplier.attrName.supply_cost", "supplyCost", FieldTypeEnum.STAR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9880, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    DELIVERY_CAPACITY("num_3", "enum.supplier.attrName.delivery_capacity", "deliveryCapacity", FieldTypeEnum.STAR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9870, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    SERVER_CAPACITY("num_4", "enum.supplier.attrName.server_capacity", "serverCapacity", FieldTypeEnum.STAR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9860, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    CREDIT_LEVEL("num_5", "enum.supplier.attrName.credit_level", "creditLevel", FieldTypeEnum.STAR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9850, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    REGISTERED_CAPITAL("num_6", "enum.supplier.attrName.registered_capital", "registeredCapital", FieldTypeEnum.NUM.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9840, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    COUNTRY("text_5", "enum.supplier.attrName.country", "country", FieldTypeEnum.COMBO.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9830, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    ADDRESS("address_1", "enum.supplier.attrName.address", "address", FieldTypeEnum.ADDRESS.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9820, 1, 0, ScreenTypeEnum.SCREEN_SEARCH.getType()),
    WEBSITE("text_6", "enum.supplier.attrName.website", "website", FieldTypeEnum.TEXT.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9810, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    ANNUAL_OUTPUT("num_7", "enum.supplier.attrName.annual_output", "annualOutput", FieldTypeEnum.NUM.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9800, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // 系统信息
    SYSTEM_INFO("other_4", "enum.supplier.attrName.system_info", "systemInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9790, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    CREATOR_ID("creatorId", "enum.supplier.attrName.creator_id", "creatorId", FieldTypeEnum.CREATORID.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9780, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    ADD_TIME("addTime", "enum.supplier.attrName.add_time", "addTime", FieldTypeEnum.ADDTIME.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 1, 0, ShowTypeEnum.ALL.getCode(), 9770, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    UPDATE_TIME("updateTime", "enum.supplier.attrName.update_time", "updateTime", FieldTypeEnum.UPDATETIME.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 1, 0, ShowTypeEnum.ALL.getCode(), 9760, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // 逻辑字段
    LAST_CONNECT_TIME("date_2", "enum.supplier.attrName.last_connect_time", "lastConnectTime", FieldTypeEnum.DATETIME.getType(), 1, 1, 1, ShowTypeEnum.LIST.getCode(), 9750, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    CONTACT("text_4", "enum.supplier.attrName.contact", "contact", FieldTypeEnum.TEXT.getType(), SetTypeEnum.DISABLE_ALL.getCode(), 0, 1, ShowTypeEnum.NONE.getCode(), 9740, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    ;

    ;

    /**
     * 英文名称
     */
    private String attr;
    /**
     * 中文名称
     */
    private String attrName;
    /**
     * 对应saas中的attr
     */
    private String saasAttr;
    /**
     * 字段类型，详见
     *
     * @see FieldTypeEnum
     */
    private Integer fieldType;
    /**
     * 重命名、判重、启用必填等权限
     * 1.重命名+字段权限
     * 2.重命名+字段权限+查重
     * 3.重命名+字段权限+启用、必填
     * 4.重命名+字段权限+查重+启用、必填
     * 注：pro中启用和必填是同一个权限，同时启用或同时关闭
     */
    private Integer setType;
    /**
     * 模板设计阶段字段是否允许编辑
     * 1：允许编辑
     * 0：不允许编辑
     */
    private Integer designEditable;
    /**
     * 字段是否显示在模板设计界面
     * 1：不显示
     * 0：显示
     */
    private Integer editHide;
    /**
     * 字段在各个界面（新建、编辑、列表、详情）的展现形式
     * 0：全部都显示
     * 1：新建编辑显示
     * 2：列表显示
     * 3：详情显示
     * 4：新建编辑、列表显示
     * 5：新建编辑、详情显示
     * 6：列表、详情显示
     * 7: 全部都不显示
     */
    private Integer showType;
    /**
     * 字段在模板设计界面的排序
     * 建议不要用连续的数字，可以用等差数列，以防以后在两个字段之间加入新字段
     */
    private Integer sort;
    /**
     * 字段在各个界面是否可见(启用)
     * 1：可见
     * 0：不可见
     * 注：字段在具体页面的可见性需要用属性和showType联合判断，在visible=1的情况下判断showType
     */
    private Integer visible;
    /**
     * 字段是否必填
     * 1：必填
     * 0：不必填
     */
    private Integer required;
    /**
     * 筛选类型
     * 1：可筛选
     * 2：不可筛选
     */
    private Integer screenType;

    SupplierEnum(String attr, String attrName, String saasAttr, Integer fieldType, Integer setType, Integer designEditable,
                 Integer editHide, Integer showType, Integer sort, Integer visible, Integer required, Integer screenType) {
        this.attr = attr;
        this.attrName = attrName;
        this.saasAttr = saasAttr;
        this.fieldType = fieldType;
        this.setType = setType;
        this.designEditable = designEditable;
        this.editHide = editHide;
        this.showType = showType;
        this.sort = sort;
        this.visible = visible;
        this.required = required;
        this.screenType = screenType;
    }

    /**
     * 根据saasAttr获取对应的中文名
     *
     * @param saasAttr
     * @author chaoxiong.lei
     * @date 22:25 2019/3/13
     * @since v1.0
     * @return saasAttr获取对应的中文名
     **/
    public static String getAttrNameBySaasAttr(String saasAttr) {
        String result = "";
        for(SupplierEnum item : values()) {
            if (Objects.equals(saasAttr, item.getSaasAttr())) {
                result = item.getAttrName();
                break;
            }
        }
        return result;
    }

    /**
     * app端详情默认标题显示字段
     *
     * @author GuoJun.HU
     * @since V1.0
     * @return List
     * @date 2019/4/8 19:21
     */
    public static List<Object> getTitleAttrList() {
        return Collections.singletonList(SUPPLIER_NAME);
    }

    /**
     * 详情默认摘要
     *
     * @author long.rao
     * @date 2019-06-27 15:47
     */
    public static List<Object> getSummaryAttrList() {
        return Arrays.asList(OWNER_ID);
    }

    /**
     * 对data内的字段拼上“data.”
     *
     * @param cache 每个枚举
     * @return java.lang.String
     * @author zcp
     * @date 2019/5/4 16:57
     * @since v1.0
     * @version v1.0
     */
    public static String getAttrConnectData(SupplierEnum cache) {
        return "data." + cache.getAttr();
    }

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }

    public static String getI18nValue(String value) {
        return I18nMessageUtil.getMessage(value);
    }
}
